package com.example.ytyproject.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.ytyproject.entity.Menu;
import com.example.ytyproject.entity.Role;
import com.example.ytyproject.entity.User;
import com.example.ytyproject.entity.vo.PermissionAllocationVo;
import com.example.ytyproject.entity.vo.R;
import com.example.ytyproject.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yg
 * @since 2023-10-27
 */
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;
    @PostMapping("/listByPage")
    public R listByPage(@RequestBody Role param) {
        return roleService.listByPage(param);
    }

    @GetMapping("/queryCurrentUserRoles")
    public R queryCurrentUserRoles(@Param("userId") String userId) {
        return roleService.queryCurrentUserRoles(userId);
    }

    @PostMapping("/addData")
    public R addData(@RequestBody Role param) {
        log.info("Role addData param: {}", JSONObject.toJSONString(param));
        roleService.addData(param);
        return R.ok();
    }

    @PostMapping("/updateData")
    public R updateData(@RequestBody Role param) {
        log.info("Role updateData param: {}", JSONObject.toJSONString(param));
        roleService.updateData(param);
        return R.ok();
    }

    @PostMapping("/permissionAllocation")
    public R permissionAllocation(@RequestBody PermissionAllocationVo allocationVo) {
        log.info("permissionAllocation permissionAllocation param: {}", JSONObject.toJSONString(allocationVo));
        roleService.permissionAllocation(allocationVo);
        return R.ok();
    }
}
